﻿@namespace AntDesign
@inherits AntDomComponentBase

<CascadingValue Value="this" IsFixed>
	@* There is no need to render the tooltip if there is no inline mode. Tooltip will be only showing menu content if menu is collapsed to icon version && only for root menu  *@
	@if (RootMenu.Mode == MenuMode.Inline && ParentMenu is null)
	{
		<Tooltip Title="@content(this)" Placement="@Placement.Right" Disabled="TooltipDisabled">
			<Unbound Context="tooltip">
                <li class="@ClassMapper.Class" role="menuitem" style="@((PaddingLeft>0? $"padding-left:{PaddingLeft}px;":"")+@Style)" @onclick="HandleOnClick" @key="Key" @ref="tooltip.Current">
                    @if (IconTemplate != null)
                    {
						<span role="img" class=" anticon anticon-container">
							@IconTemplate
						</span>
                    }
                    else if (Icon != null)
                    {
                        <Icon Type="@Icon" />
                    }
                    <span class="ant-menu-title-content">
                        @if (RouterLink == null)
                        {
                            @content(this)
                        }
                        else
                        {
                            <MenuLink Href="@RouterLink" Match="@RouterMatch">@content(this)</MenuLink>
                        }
                    </span>
                </li>
			</Unbound>
		</Tooltip>
	}
	else
	{
		<li class="@ClassMapper.Class" role="menuitem" style="@((PaddingLeft>0? $"padding-left:{PaddingLeft}px;":"")+@Style)" @onclick="HandleOnClick" @key="Key">
			@if (Icon != null)
			{
				<Icon Type="@Icon" />
			}

			<span class="ant-menu-title-content">
				@if (RouterLink == null)
				{
					@content(this)
				}
				else
				{
					<MenuLink Href="@RouterLink" Match="@RouterMatch">@content(this)</MenuLink>
				}
			</span>
		</li>
	}
</CascadingValue>

@code {
	RenderFragment<MenuItem> content = item =>
	@<Template>
		@if (item.Title != null)
		{
			@item.Title
		}
		else
		{
			@item.ChildContent
		}
	</Template>
	;
}
